// export const URL = 'http://aztest.niuniuhaohan.com' // 测试站
export const URL = 'https://zhishengshangbao.xman56.com' // 正式站

export function requst(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `${URL}${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}

export function requst2(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://api.regenai.com${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}

export function requst3(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://api.deepseek.com${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}

export function requst4(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `http://api.voice.ihuyi.com${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}

// 火山引擎豆包AI接口示例
// curl https://ark.cn-beijing.volces.com/api/v3/chat/completions \
//   -H "Content-Type: application/json" \
//   -H "Authorization: Bearer c7d3f0d6-7999-4389-8018-a735e04c85fa" \
//   -d $'
//   {
//     "model": "doubao-1-5-ui-tars-250428",
//     "messages": [
//         {
//             "content": [
//                 {
//                     "image_url": {
//                         "url": "https://ark-project.tos-cn-beijing.ivolces.com/images/view.jpeg"
//                     },
//                     "type": "image_url"
//                 },
//                 {
//                     "text": "图片主要讲了什么?",
//                     "type": "text"
//                 }
//             ],
//             "role": "user"
//         }
//     ]
// }
// '

// 火山引擎(豆包AI)--生产环境服务器
export function requst5(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://zsdakehu.xman56.com${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}

// OA物品领用
export function requst6(url, prms, method, header) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: `https://zhishengoa.xman56.com${url}`,
			data: { ...prms },
			method: method || 'GET',
			header,
			success: res => {
				resolve(res.data)
			},
			fail: err => {
				uni.showToast({ title: `${JSON.stringify(err)}`, icon: 'none' })
				reject(err)
			},
			complete: res => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
				// console.log(`响应拦截器----${url}---`, res);
				if (res.statusCode == 401) { // 未登录,身份认证失败
					uni.removeStorageSync('userinfo');
					uni.redirectTo({ url: '/pages/login/login' })
				}
			}
		})
	})
}